package com.xh.model.dto;

import cn.hutool.core.collection.CollUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.xh.model.table.PosterItem;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.assertj.core.util.Lists;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 海报组件属性表
 * </p>
 *
 * @author wen
 * @since 2021-07-08
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "PosterItem对象", description = "海报组件属性表")
public class PosterItemDTO {

    @ApiModelProperty(value = "主键ID")
    private Long id;

    @ApiModelProperty(value = "组件类型")
    private String t;

    @ApiModelProperty(value = "组件名称")
    private String name;

    @ApiModelProperty(value = "随机字符")
    private String uuid;

    @ApiModelProperty(value = "坐标X")
    private Integer x;

    @ApiModelProperty(value = "坐标Y")
    private Integer y;

    @ApiModelProperty(value = "宽")
    private Integer w;

    @ApiModelProperty(value = "高")
    private Integer h;

    @ApiModelProperty(value = "坐标Z")
    private Integer z;

    @ApiModelProperty(value = "坐标S")
    private Integer s;

    @ApiModelProperty(value = "颜色")
    private String c;

    @ApiModelProperty(value = "背景图URL")
    private String bgc;

    @ApiModelProperty(value = "静态参数")
    private String v;

    @ApiModelProperty(value = "动态参数")
    private String vd;

    private String fn;

    private Integer st;

    @ApiModelProperty(value = "是否激活状态[1-是 0-否]")
    private Integer active;

    @ApiModelProperty(value = "海报记录表ID")
    private Long posterId;

    public static List<PosterItemDTO> convert(List<PosterItem> posterItems) {
        if (CollUtil.isNotEmpty(posterItems)) {
            return posterItems.stream().map(item -> {
                PosterItemDTO posterItemDTO = new PosterItemDTO();
                BeanUtils.copyProperties(item, posterItemDTO);
                posterItemDTO.setC(item.getColor());
                return posterItemDTO;
            }).collect(Collectors.toList());
        }
        return Lists.newArrayList();
    }
}
